﻿using System.Data;

namespace Dz.WorkerService.Utils
{
    internal class InvUtils :BaseUtils
    {
        
        private List<string> invs = new List<string>();

        private static readonly Lazy<InvUtils> instance = new Lazy<InvUtils>(() => new InvUtils());

        public static InvUtils Instance => instance.Value;


        protected override void Init() 
        {
            string sql = @"select a.code + '/' + b.code 
                        from CBO_ItemMaster a
                        inner join Base_Organization b on a.org = b.ID
                        where lower(a.DescFlexField_PrivateDescSeg12)='true'";

            DataTable reader = sqlUtils.FillSync(sql);

            foreach (DataRow row in reader.Rows) 
            {
                invs.Add(row[0].ToString());
            }
        }

        public bool IsExists(string invCode, string org)
        {
            return invs.Contains($"{invCode}/{org}");
        }

        public override void ReLoad()
        {
            invs.Clear();
            Init();
        }
    }
}
